package com.heatingcharge.controller.charge;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.ChargeInfoDTO;
import com.heatingcharge.dto.ChargeStatisticInfoDTO;
import com.heatingcharge.dto.CurrentDayChargeInfo;
import com.heatingcharge.dto.ZoneClearOffDTO;
import com.heatingcharge.entity.charge.ChargeInfo;
import com.heatingcharge.param.ChargeInfoParam;
import com.heatingcharge.param.SearchParam;
import com.heatingcharge.security.JwtUser;
import com.heatingcharge.security.util.SecurityUtil;
import com.heatingcharge.service.charge.IChargeInfoService;
import com.heatingcharge.service.charge.IClearOffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-10-17
 */
@RestController
@RequestMapping("/charge-info")
public class ChargeInfoController {
    @Autowired
    IChargeInfoService chargeInfoService;
    @Autowired
    IClearOffService clearOffService;

    //分页获取
    @GetMapping
    public R getChargeInfo(Page page,SearchParam searchParam){
        return R.ok(chargeInfoService.getChargeInfo(page,searchParam));
    }

    //获取查询条件的所有记录
    @GetMapping("/list")
    public R getChargeInfo(SearchParam searchParam){
        return R.ok(chargeInfoService.getChargeInfo(searchParam));
    }

    /**
     * 获取指定住户的缴费信息
     * @return
     */
    @GetMapping("/house/{id}")
    public R getChargeInfo(@PathVariable("id") Integer id){
        SearchParam searchParam = SearchParam.builder()
                .houseId(id)
                .build();
        return R.ok(chargeInfoService.getChargeInfo(searchParam));
    }


    /**
     * 缴费
     * @param chargeInfoParam
     * @return
     */
    @PostMapping("/charge")
    public R charge(@RequestBody ChargeInfoParam chargeInfoParam){
        if(chargeInfoService.charge(chargeInfoParam)>0){
            return R.ok();
        }
        return R.error();
    }

    @GetMapping("/currentDay")
    public R getCurrentDayInfo(){
        CurrentDayChargeInfo currentDayChargeInfo=chargeInfoService.getCurrentDayInfo();
        return R.ok(currentDayChargeInfo);
    }

    /**
     * 获取当前供暖季的信息
     * @return
     */
    @GetMapping("/currentSession")
    public R getCurrentSessionInfo(){
        SearchParam searchParam=new SearchParam();
        searchParam.setHeatYearId(3);//TODO
        ZoneClearOffDTO allZonesStatistics = clearOffService.getAllZonesStatistics(searchParam);
        return R.ok(allZonesStatistics);
    }
    @GetMapping("/chargeMode")
    public R getChargeMode(){
        ChargeStatisticInfoDTO chargeStatisticInfoDTO=chargeInfoService.getChargeMode();
        return R.ok(chargeStatisticInfoDTO);
    }
}

